#include "enemyplane.h"

EnemyPlane::EnemyPlane()
{
    m_Interval1 = 0;
    m_Interval2 = 0;
}

/* 敌机更新 */
void EnemyPlane::updatePosition()
{
    //敌机1更新
    for(int i=0; i < ENEMY1_NUM; i++)
    {
        m_Enemy1[i].updatePosition();
    }
    //敌机2更新
    for(int i=0; i < ENEMY2_NUM; i++)
    {
        m_Enemy2[i].updatePosition();
    }

}

/* 敌机放飞 */
void EnemyPlane::flyEnemys()
{
    m_Interval1++;
    m_Interval2++;


    //敌机1放飞
    if(m_Interval1 >= ENEMY1_INTERVAL)
    {
        m_Interval1  = 0; //重置间隔
        for(int i=0; i < ENEMY1_NUM; i++)
        {
            if(m_Enemy1[i].m_Free)
            {
                m_Enemy1[i].m_Free = false;
                m_Enemy1[i].m_X = rand() % (GAME_WIDTH-m_Enemy1[i].m_Plane.width());
                m_Enemy1[i].m_Y = 0 - m_Enemy1[i].m_Plane.height();
                break;
            }
        }
    }
    //敌机2放飞
    if(m_Interval2 >= ENEMY2_INTERVAL)
    {
        m_Interval2  = 0; //重置间隔
        for(int i=0; i < ENEMY2_NUM; i++)
        {
            if(m_Enemy2[i].m_Free)
            {
                //属性初始化
                m_Enemy2[i].m_Free = false;
                m_Enemy2[i].m_life = ENEMY2_LIFE;

                m_Enemy2[i].m_X = rand() % (GAME_WIDTH-m_Enemy2[i].m_Plane.width());
                m_Enemy2[i].m_Y = 0 - m_Enemy2[i].m_Plane.height();
                break;
            }
        }
    }

}
